<template>
  <img alt="Vue logo" src="./assets/logo.png" />
  <HelloWorld
    msg="Welcome to Your Vue.js + TypeScript App"
    :name="'小明'"
    :age="12"
  />
  {{ state.count }}--{{ state2 }}
</template>

<script lang="ts">
import { defineComponent, reactive, ref, computed, watchEffect } from "vue"
import HelloWorld from "./components/HelloWorld.vue"
// defineComponent 函数组件
export default defineComponent({
  name: "App",
  mounted() {
    console.log(this.state.count, "mounted")
  },
  // 俩个参数 该函数只会执行一次
  setup(props, { slots, attrs, emit }) {
    let state = reactive({
      count: 1,
    })
    let state2 = ref(0)
    const computedName = computed(() => {
      return state2.value + 10
    })
    setInterval(() => {
      state.count++
      state2.value++
    }, 1000)
    watchEffect(() => {
      console.log(state2.value)
      console.log(state.count)
      console.log("---")
      // 2
      //12
      // ---
    })
    return {
      state,
      state2: computedName,
    }
  },
  components: {
    HelloWorld,
  },
})
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
